package com.example.serviceandroidjava.bindServiceBinder;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import androidx.annotation.Nullable;

import java.util.Random;

public class LocalService extends Service {
    private final IBinder binder = new LocalBinder();
    private final Random mGenerator = new Random();

    ///返回LocalService实例，从而客户端可以调用服务中的公共方法
    public class LocalBinder extends Binder {
        public LocalService getService() {
            return LocalService.this;
        }
    }

    //返回binder
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    ///公共方法
    public int getRandomNumber() {
        return mGenerator.nextInt(100);
    }
}
